package com.zf.zffencheng.interceptor;

import com.zf.zffencheng.exception.Error_;
import com.zf.zffencheng.exception.ResultException;
import com.zf.zffencheng.model.vo.AdminLoginInfoVo;
import com.zf.zffencheng.service.AdminService;
import com.zf.zffencheng.util.UserContextUtils;
import lombok.extern.log4j.Log4j2;
import org.redisson.api.RBucket;
import org.redisson.api.RedissonClient;
import org.redisson.codec.JsonJacksonCodec;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;

/**
 * ClassName: interceptor <br/>
 * Description:  <br/>
 * date: 2021/5/10 9:32<br/>
 *
 * @author william <br/>
 */
@Component
@Log4j2
public class TenantInterceptor extends HandlerInterceptorAdapter {
    @Autowired
    private RedissonClient redissonClient;

    public static final String AUTHORIZATION_HEADER ="Authorization";
    public static final String BEARER ="Bearer ";
    public static final int BEARER_LENGTH = BEARER.length();
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        AdminLoginInfoVo currentAdminInfo = UserContextUtils.getCurrentAdminInfo();
        if (currentAdminInfo == null) {
            throw new ResultException(Error_.AUTHORIZATION_FAIL);
        }
        if (currentAdminInfo.getAdminType() != 2) {
            throw new ResultException(Error_.AUTHORIZATION_FAIL);
        }
        return true;
    }

}
